package com.homework10;

import java.io.*;

public class demo {
    public static void main(String[] args) throws IOException {
        demo01();
    }

    private static void demo01() throws IOException {
        File file = new File("D:\\dir");
        file.mkdir();
        for (int i = 1; i <=10; i++) {
            new File("D:\\dir\\"+(i)+".txt").createNewFile();
        }
        File file1 = new File("D:\\dir2");
        file1.mkdir();
        File[] files = file.listFiles();//获取dir中的每一个文件
        //获取文件数组的每一个文件的字节输入流
        //获取文件里面的内容存到Dir2目录

        for (File file2 : files) {
            if(file2.isFile()){
                FileInputStream fileInputStream = new FileInputStream(file2);
                FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\\dir2",file2.getName()));//目录二·
                int len=0;
                byte[] bytes = new byte[1024];
                while ((len=fileInputStream.read(bytes))!=-1){
                    fileOutputStream.write(bytes);
                }
                fileInputStream.close();
                fileOutputStream.close();
            }
        }

    }
}
